package listener;

import javax.servlet.*;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author 陈华旺
 * @version 1.0
 * @date 2023年11月24日 9:04
 * @Description TODO
 */
@WebListener
public class TestListener implements ServletRequestListener, ServletContextListener {

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        HttpServletRequest req = (HttpServletRequest) servletRequestEvent.getServletRequest();
        System.out.println( "请求"+req.getServletPath()+"初始化"+new Date() );
    }

    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        HttpServletRequest req = (HttpServletRequest) servletRequestEvent.getServletRequest();
        System.out.println( "请求"+req.getServletPath()+"销毁"+new Date() );
    }

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext app = servletContextEvent.getServletContext();
        System.out.println("应用程序初始化:"+app.getContextPath());
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        System.out.println("应用程序销毁");
    }
}
